{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "20aeb085-c90e-46d7-8752-44f53effb1a4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "开始生成第三部分图表 (21-30)...\n",
      "✅ 图表 21 生成完成\n",
      "✅ 图表 22 生成完成\n",
      "✅ 图表 23 生成完成\n",
      "✅ 图表 24 生成完成\n",
      "✅ 图表 25 生成完成\n",
      "✅ 图表 26 生成完成\n",
      "✅ 图表 27 生成完成\n",
      "✅ 图表 28 生成完成\n",
      "✅ 图表 29 生成完成\n",
      "✅ 图表 30 生成完成\n",
      "🎉 第三部分图表已保存到: D:\\数据分析及可视化\\图表\n",
      "✨ 所有30个图表生成完成！\n"
     ]
    }
   ],
   "source": [
    "# visualization_part3_fixed.py\n",
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "import seaborn as sns\n",
    "import numpy as np\n",
    "from matplotlib.patches import Patch, Rectangle, FancyBboxPatch, Wedge, Circle\n",
    "import matplotlib as mpl\n",
    "from scipy import stats\n",
    "import os\n",
    "\n",
    "# 设置中文字体\n",
    "plt.rcParams['font.sans-serif'] = ['SimHei', 'Microsoft YaHei']\n",
    "plt.rcParams['axes.unicode_minus'] = False\n",
    "\n",
    "# 创建保存目录\n",
    "output_dir = r\"D:\\数据分析及可视化\\图表\"\n",
    "os.makedirs(output_dir, exist_ok=True)\n",
    "\n",
    "class VisualizationPart3:\n",
    "    def __init__(self, data_path):\n",
    "        self.df = pd.read_excel(data_path)\n",
    "        self.colors = ['#FF6B6B', '#4ECDC4', '#45B7D1', '#96CEB4', '#FFEAA7', \n",
    "                      '#DDA0DD', '#98D8C8', '#F7DC6F', '#BB8FCE', '#85C1E9']\n",
    "        \n",
    "    def chart21_bar_line_combo(self):\n",
    "        \"\"\"21. 柱形折线图 - 销售量和同比增长\"\"\"\n",
    "        fig, ax1 = plt.subplots(figsize=(12, 6))  # 减小尺寸\n",
    "        \n",
    "        # 模拟年度销售数据\n",
    "        years = ['2017', '2018', '2019', '2020', '2021', '2022']\n",
    "        sales = [1603, 2106, 2406, 3265, 3721, 3921]\n",
    "        growth_rates = [0.27, 0.31, 0.14, 0.36, 0.14, 0.05]\n",
    "        \n",
    "        # 左侧Y轴 - 销售量（柱形图）\n",
    "        bars = ax1.bar(years, sales, color='#3498DB', alpha=0.7, width=0.6)\n",
    "        ax1.set_ylabel('销售量 (件)', fontsize=10, color='#3498DB')\n",
    "        ax1.tick_params(axis='y', labelcolor='#3498DB')\n",
    "        \n",
    "        # 添加销售量数值标签\n",
    "        for bar, value in zip(bars, sales):\n",
    "            height = bar.get_height()\n",
    "            ax1.text(bar.get_x() + bar.get_width()/2, height + 50, \n",
    "                    f'{value:,}', ha='center', va='bottom', fontsize=8,\n",
    "                    color='#3498DB', fontweight='bold')\n",
    "        \n",
    "        # 右侧Y轴 - 增长率（折线图）\n",
    "        ax2 = ax1.twinx()\n",
    "        line = ax2.plot(years, growth_rates, 'ro-', linewidth=2, markersize=6, \n",
    "                       label='同比增长率')\n",
    "        ax2.set_ylabel('同比增长率', fontsize=10, color='red')\n",
    "        ax2.tick_params(axis='y', labelcolor='red')\n",
    "        ax2.set_ylim(0, max(growth_rates) * 1.2)\n",
    "        \n",
    "        # 添加增长率数值标签\n",
    "        for i, rate in enumerate(growth_rates):\n",
    "            ax2.annotate(f'{rate:.0%}', xy=(i, rate), xytext=(i, rate + 0.02),\n",
    "                        ha='center', va='bottom', fontsize=8, color='red',\n",
    "                        fontweight='bold')\n",
    "        \n",
    "        plt.title('年度销售量及同比增长率', fontsize=14, fontweight='bold', pad=15)\n",
    "        ax1.set_xlabel('年份', fontsize=10)\n",
    "        ax1.grid(axis='y', alpha=0.3)\n",
    "        \n",
    "        plt.tight_layout()\n",
    "        plt.savefig(f'{output_dir}/21_柱形折线图.png', dpi=150, bbox_inches='tight')  # 降低DPI\n",
    "        plt.close()\n",
    "        \n",
    "    def chart22_target_bar(self):\n",
    "        \"\"\"22. 目标柱形图 - 商品销售目标完成情况\"\"\"\n",
    "        fig, ax1 = plt.subplots(figsize=(10, 6))  # 减小尺寸\n",
    "        \n",
    "        # 商品销售数据\n",
    "        products = ['口红', '面膜', '隔离', '防晒', '精华', '面霜']\n",
    "        actual_sales = [653, 523, 648, 856, 714, 785]\n",
    "        target_sales = [700, 500, 600, 900, 600, 600]\n",
    "        \n",
    "        x = np.arange(len(products))\n",
    "        width = 0.35\n",
    "        \n",
    "        # 绘制实际销售和目标销售柱形\n",
    "        bars1 = ax1.bar(x - width/2, actual_sales, width, \n",
    "                       label='实际销量', color='#3498DB', alpha=0.8)\n",
    "        bars2 = ax1.bar(x + width/2, target_sales, width, \n",
    "                       label='目标销量', color='#E74C3C', alpha=0.6)\n",
    "        \n",
    "        # 添加数值标签\n",
    "        for i, (actual, target) in enumerate(zip(actual_sales, target_sales)):\n",
    "            # 实际销量标签\n",
    "            ax1.text(i - width/2, actual + 20, f'{actual}', ha='center', va='bottom', \n",
    "                    fontsize=8, color='#3498DB', fontweight='bold')\n",
    "            # 目标销量标签\n",
    "            ax1.text(i + width/2, target + 20, f'{target}', ha='center', va='bottom', \n",
    "                    fontsize=8, color='#E74C3C', fontweight='bold')\n",
    "            \n",
    "            # 计算完成率\n",
    "            completion = actual / target\n",
    "            color = 'green' if completion >= 1 else 'red'\n",
    "            ax1.text(i, max(actual, target) + 50, f'{completion:.0%}', \n",
    "                    ha='center', va='bottom', fontsize=9, color=color, fontweight='bold')\n",
    "        \n",
    "        plt.title('商品销售目标完成情况', fontsize=14, fontweight='bold', pad=15)\n",
    "        plt.xlabel('商品', fontsize=10)\n",
    "        plt.ylabel('销量', fontsize=10)\n",
    "        plt.xticks(x, products)\n",
    "        plt.legend(loc='upper left')\n",
    "        plt.grid(axis='y', alpha=0.3)\n",
    "        \n",
    "        plt.tight_layout()\n",
    "        plt.savefig(f'{output_dir}/22_目标柱形图.png', dpi=150, bbox_inches='tight')\n",
    "        plt.close()\n",
    "        \n",
    "    def chart23_bullet_chart(self):\n",
    "        \"\"\"23. 子弹图 - 商品销售绩效\"\"\"\n",
    "        fig, ax = plt.subplots(figsize=(10, 6))  # 减小尺寸\n",
    "        \n",
    "        # 商品绩效数据\n",
    "        products = ['口红', '面膜', '隔离', '防晒', '精华', '面霜']\n",
    "        actual_sales = [653, 523, 648, 856, 714, 785]\n",
    "        targets = [700, 500, 600, 900, 600, 600]\n",
    "        \n",
    "        # 绩效区间\n",
    "        poor = [400] * len(products)\n",
    "        fair = [500] * len(products)\n",
    "        good = [600] * len(products)\n",
    "        \n",
    "        colors = ['#EDE7F6', '#D1C4E9', '#B39DDB']\n",
    "        \n",
    "        # 绘制绩效区间背景\n",
    "        for i in range(len(products)):\n",
    "            # 绩效区间\n",
    "            ax.barh(i, good[i], color=colors[2], alpha=0.3, height=0.6)\n",
    "            ax.barh(i, fair[i], color=colors[1], alpha=0.3, height=0.6)\n",
    "            ax.barh(i, poor[i], color=colors[0], alpha=0.3, height=0.6)\n",
    "            \n",
    "            # 实际销售（子弹）\n",
    "            ax.barh(i, actual_sales[i], color='#2E7D32', height=0.3, alpha=0.8)\n",
    "            \n",
    "            # 目标线\n",
    "            ax.axvline(x=targets[i], ymin=(i-0.3)/len(products), \n",
    "                      ymax=(i+0.3)/len(products), color='red', \n",
    "                      linewidth=2, linestyle='--', alpha=0.8)\n",
    "            \n",
    "            # 添加数值标签\n",
    "            ax.text(actual_sales[i] + 20, i, f'{actual_sales[i]}', \n",
    "                   va='center', fontsize=8, fontweight='bold', color='#2E7D32')\n",
    "        \n",
    "        # 设置Y轴\n",
    "        ax.set_yticks(range(len(products)))\n",
    "        ax.set_yticklabels(products, fontsize=10)\n",
    "        ax.set_xlabel('销量', fontsize=10)\n",
    "        ax.set_title('商品销售绩效子弹图', fontsize=14, fontweight='bold', pad=15)\n",
    "        ax.grid(axis='x', alpha=0.3)\n",
    "        \n",
    "        plt.tight_layout()\n",
    "        plt.savefig(f'{output_dir}/23_子弹图.png', dpi=150, bbox_inches='tight')\n",
    "        plt.close()\n",
    "        \n",
    "    def chart24_column_circle(self):\n",
    "        \"\"\"24. 柱形圆 - 区域销售对比\"\"\"\n",
    "        fig, ax = plt.subplots(figsize=(10, 6))\n",
    "        \n",
    "        # 区域销售数据\n",
    "        regions = ['华北', '华南', '东北', '西北', '西南', '华东']\n",
    "        sales = [2354, 1902, 3524, 2698, 2896, 2563]\n",
    "        growth_rates = [0.12, 0.25, 0.16, 0.21, 0.18, 0.25]\n",
    "        \n",
    "        # 创建柱形圆图\n",
    "        for i, (region, sale, growth) in enumerate(zip(regions, sales, growth_rates)):\n",
    "            # 柱形（圆形表示）\n",
    "            circle = Circle((i, sale/200), radius=0.2, \n",
    "                          facecolor=self.colors[i], alpha=0.8, \n",
    "                          edgecolor='white', linewidth=1)\n",
    "            ax.add_artist(circle)\n",
    "            \n",
    "            # 添加销售数值\n",
    "            ax.text(i, sale/200, f'{sale:,}', ha='center', va='center', \n",
    "                   fontsize=8, fontweight='bold', color='white')\n",
    "            \n",
    "            # 添加增长率指示器\n",
    "            growth_color = 'green' if growth > 0.15 else 'orange'\n",
    "            growth_marker = '↑' if growth > 0.15 else '→'\n",
    "            \n",
    "            ax.text(i, sale/200 + 0.3, f'{growth_marker} {growth:.0%}', \n",
    "                   ha='center', va='bottom', fontsize=9, color=growth_color,\n",
    "                   fontweight='bold')\n",
    "            \n",
    "            # 区域标签\n",
    "            ax.text(i, -0.3, region, ha='center', va='top', fontsize=10)\n",
    "        \n",
    "        ax.set_xlim(-1, len(regions))\n",
    "        ax.set_ylim(-0.5, max(sales)/200 + 0.5)\n",
    "        ax.set_aspect('equal')\n",
    "        ax.axis('off')\n",
    "        \n",
    "        plt.title('区域销售对比 - 柱形圆图', fontsize=14, fontweight='bold', pad=15)\n",
    "        \n",
    "        plt.tight_layout()\n",
    "        plt.savefig(f'{output_dir}/24_柱形圆.png', dpi=150, bbox_inches='tight')\n",
    "        plt.close()\n",
    "        \n",
    "    def chart25_clustered_bar_line(self):\n",
    "        \"\"\"25. 簇状柱形折线图 - 区域销售对比\"\"\"\n",
    "        fig, ax1 = plt.subplots(figsize=(10, 6))\n",
    "        \n",
    "        # 区域销售数据\n",
    "        regions = ['华北', '华南', '东北', '西北', '西南', '华东']\n",
    "        sales_2022 = [2354, 1902, 3524, 2698, 2896, 2563]\n",
    "        sales_2021 = [2021, 1563, 3213, 2531, 2631, 2361]\n",
    "        growth_rates = [0.16, 0.22, 0.10, 0.07, 0.10, 0.09]\n",
    "        \n",
    "        x = np.arange(len(regions))\n",
    "        width = 0.35\n",
    "        \n",
    "        # 簇状柱形图\n",
    "        bars1 = ax1.bar(x - width/2, sales_2022, width, \n",
    "                       label='2022年销量', color='#3498DB', alpha=0.8)\n",
    "        bars2 = ax1.bar(x + width/2, sales_2021, width, \n",
    "                       label='2021年销量', color='#85C1E9', alpha=0.8)\n",
    "        \n",
    "        # 添加数值标签\n",
    "        for i, (sales22, sales21, rate) in enumerate(zip(sales_2022, sales_2021, growth_rates)):\n",
    "            # 2022年销量\n",
    "            ax1.text(i - width/2, sales22 + 50, f'{sales22:,}', ha='center', va='bottom', \n",
    "                    fontsize=8, color='#3498DB', fontweight='bold')\n",
    "            # 2021年销量\n",
    "            ax1.text(i + width/2, sales21 + 50, f'{sales21:,}', ha='center', va='bottom', \n",
    "                    fontsize=8, color='#85C1E9', fontweight='bold')\n",
    "            # 增长率\n",
    "            ax1.text(i, max(sales22, sales21) + 150, f'{rate:.1%}', ha='center', va='bottom', \n",
    "                    fontsize=9, color='red', fontweight='bold')\n",
    "        \n",
    "        plt.title('区域销售对比', fontsize=14, fontweight='bold', pad=15)\n",
    "        ax1.set_xlabel('区域', fontsize=10)\n",
    "        ax1.set_ylabel('销售额 (元)', fontsize=10)\n",
    "        ax1.set_xticks(x)\n",
    "        ax1.set_xticklabels(regions)\n",
    "        ax1.grid(axis='y', alpha=0.3)\n",
    "        ax1.legend()\n",
    "        \n",
    "        plt.tight_layout()\n",
    "        plt.savefig(f'{output_dir}/25_簇状柱形折线图.png', dpi=150, bbox_inches='tight')\n",
    "        plt.close()\n",
    "        \n",
    "    def chart26_composite_bar(self):\n",
    "        \"\"\"26. 复合柱形图 - 月度与季度销售\"\"\"\n",
    "        fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(12, 8))\n",
    "        \n",
    "        # 月度销售数据\n",
    "        months = ['1月', '2月', '3月', '4月', '5月', '6月']\n",
    "        monthly_sales = [2354, 1902, 3524, 2698, 2896, 2563]\n",
    "        \n",
    "        # 季度销售数据\n",
    "        quarterly_sales = [\n",
    "            sum(monthly_sales[0:3]),  # Q1\n",
    "            sum(monthly_sales[3:6]),  # Q2\n",
    "        ]\n",
    "        \n",
    "        # 上部：月度柱形图\n",
    "        bars1 = ax1.bar(months, monthly_sales, color='#3498DB', alpha=0.7)\n",
    "        ax1.set_ylabel('月度销售额 (元)', fontsize=10)\n",
    "        ax1.set_title('月度销售详情', fontsize=12, fontweight='bold')\n",
    "        ax1.grid(axis='y', alpha=0.3)\n",
    "        \n",
    "        # 添加月度数值标签\n",
    "        for bar, value in zip(bars1, monthly_sales):\n",
    "            ax1.text(bar.get_x() + bar.get_width()/2, value + 100, \n",
    "                    f'{value:,}', ha='center', va='bottom', fontsize=8)\n",
    "        \n",
    "        # 下部：季度柱形图\n",
    "        quarters = ['第一季度', '第二季度']\n",
    "        bars2 = ax2.bar(quarters, quarterly_sales, color='#E74C3C', alpha=0.7)\n",
    "        ax2.set_ylabel('季度销售额 (元)', fontsize=10)\n",
    "        ax2.set_title('季度销售汇总', fontsize=12, fontweight='bold')\n",
    "        ax2.grid(axis='y', alpha=0.3)\n",
    "        \n",
    "        # 添加季度数值标签\n",
    "        for bar, value in zip(bars2, quarterly_sales):\n",
    "            ax2.text(bar.get_x() + bar.get_width()/2, value + 500, \n",
    "                    f'{value:,}', ha='center', va='bottom', fontsize=9, fontweight='bold')\n",
    "        \n",
    "        plt.suptitle('月度与季度销售分析', fontsize=14, fontweight='bold', y=0.95)\n",
    "        plt.tight_layout()\n",
    "        plt.savefig(f'{output_dir}/26_复合柱形图.png', dpi=150, bbox_inches='tight')\n",
    "        plt.close()\n",
    "        \n",
    "    def chart27_bead_chart(self):\n",
    "        \"\"\"27. 滑珠图 - 区域完成率\"\"\"\n",
    "        plt.figure(figsize=(10, 6))\n",
    "        \n",
    "        # 区域完成率数据\n",
    "        regions = ['华东', '西北', '东北', '华北', '华南']\n",
    "        completion_rates = [0.35, 0.51, 0.62, 0.74, 0.86]\n",
    "        \n",
    "        y_pos = np.arange(len(regions))\n",
    "        \n",
    "        # 绘制背景线\n",
    "        for i in range(len(regions)):\n",
    "            plt.hlines(y=i, xmin=0, xmax=1, color='gray', alpha=0.3, linewidth=6)\n",
    "        \n",
    "        # 绘制完成率滑珠\n",
    "        plt.scatter(completion_rates, y_pos, s=120, \n",
    "                   color='#3498DB', alpha=0.8, \n",
    "                   edgecolors='white', linewidth=2, zorder=5)\n",
    "        \n",
    "        # 添加数值标签\n",
    "        for i, (region, rate) in enumerate(zip(regions, completion_rates)):\n",
    "            plt.text(rate, i + 0.2, f'{rate:.0%}', ha='center', va='bottom', \n",
    "                    fontsize=9, fontweight='bold', color='#3498DB')\n",
    "            plt.text(-0.1, i, region, ha='right', va='center', \n",
    "                    fontsize=10, fontweight='bold')\n",
    "        \n",
    "        # 添加参考线\n",
    "        plt.axvline(x=0.5, color='red', linestyle='--', alpha=0.5, linewidth=1)\n",
    "        \n",
    "        plt.title('区域任务完成率 - 滑珠图', fontsize=14, fontweight='bold', pad=15)\n",
    "        plt.xlabel('完成率', fontsize=10)\n",
    "        plt.ylabel('区域', fontsize=10)\n",
    "        plt.yticks(y_pos, regions)\n",
    "        plt.xlim(0, 1)\n",
    "        plt.grid(False)\n",
    "        \n",
    "        plt.tight_layout()\n",
    "        plt.savefig(f'{output_dir}/27_滑珠图.png', dpi=150, bbox_inches='tight')\n",
    "        plt.close()\n",
    "        \n",
    "    def chart28_comparison_bead_chart(self):\n",
    "        \"\"\"28. 对比滑珠图 - 年度完成率对比\"\"\"\n",
    "        plt.figure(figsize=(10, 6))\n",
    "        \n",
    "        # 两年完成率数据\n",
    "        regions = ['华东', '西北', '东北', '华北', '华南']\n",
    "        rates_2022 = [0.35, 0.51, 0.62, 0.74, 0.86]\n",
    "        rates_2021 = [0.45, 0.39, 0.53, 0.69, 0.92]\n",
    "        \n",
    "        y_pos = np.arange(len(regions))\n",
    "        \n",
    "        # 绘制背景线\n",
    "        for i in range(len(regions)):\n",
    "            plt.hlines(y=i, xmin=0, xmax=1, color='gray', alpha=0.3, linewidth=6)\n",
    "        \n",
    "        # 绘制两年滑珠\n",
    "        plt.scatter(rates_2022, y_pos - 0.1, s=100, \n",
    "                   color='#3498DB', alpha=0.8, \n",
    "                   edgecolors='white', linewidth=2, zorder=5, label='2022年')\n",
    "        plt.scatter(rates_2021, y_pos + 0.1, s=100, \n",
    "                   color='#E74C3C', alpha=0.8, \n",
    "                   edgecolors='white', linewidth=2, zorder=5, label='2021年')\n",
    "        \n",
    "        # 添加连接线显示变化\n",
    "        for i, (rate22, rate21) in enumerate(zip(rates_2022, rates_2021)):\n",
    "            plt.plot([rate21, rate22], [i+0.1, i-0.1], 'k-', alpha=0.5, linewidth=1)\n",
    "            \n",
    "            # 计算变化\n",
    "            change = rate22 - rate21\n",
    "            change_color = 'green' if change > 0 else 'red'\n",
    "            change_symbol = '↗' if change > 0 else '↘'\n",
    "            \n",
    "            # 添加变化标注\n",
    "            mid_x = (rate21 + rate22) / 2\n",
    "            plt.text(mid_x, i, f'{change_symbol}{abs(change):.0%}', \n",
    "                    ha='center', va='center', fontsize=8, color=change_color)\n",
    "        \n",
    "        # 添加区域标签\n",
    "        for i, region in enumerate(regions):\n",
    "            plt.text(-0.1, i, region, ha='right', va='center', \n",
    "                    fontsize=10, fontweight='bold')\n",
    "        \n",
    "        plt.title('年度完成率对比', fontsize=14, fontweight='bold', pad=15)\n",
    "        plt.xlabel('完成率', fontsize=10)\n",
    "        plt.ylabel('区域', fontsize=10)\n",
    "        plt.yticks(y_pos, regions)\n",
    "        plt.xlim(0, 1)\n",
    "        plt.grid(False)\n",
    "        plt.legend()\n",
    "        \n",
    "        plt.tight_layout()\n",
    "        plt.savefig(f'{output_dir}/28_对比滑珠图.png', dpi=150, bbox_inches='tight')\n",
    "        plt.close()\n",
    "        \n",
    "    def chart29_advanced_dashboard(self):\n",
    "        \"\"\"29. 高级仪表盘 - 综合业务指标\"\"\"\n",
    "        fig = plt.figure(figsize=(12, 8))\n",
    "        \n",
    "        # 创建子图布局\n",
    "        gs = fig.add_gridspec(2, 2)\n",
    "        \n",
    "        # 1. 核心指标\n",
    "        ax1 = fig.add_subplot(gs[0, 0])\n",
    "        ax1.text(0.5, 0.5, '1,254,368', ha='center', va='center', \n",
    "                fontsize=20, fontweight='bold', color='#2C3E50')\n",
    "        ax1.text(0.5, 0.3, '总销售额 (元)', ha='center', va='center', \n",
    "                fontsize=12, color='#7F8C8D')\n",
    "        ax1.set_xlim(0, 1)\n",
    "        ax1.set_ylim(0, 1)\n",
    "        ax1.axis('off')\n",
    "        \n",
    "        # 2. 完成率\n",
    "        ax2 = fig.add_subplot(gs[0, 1])\n",
    "        completion = 0.76\n",
    "        # 使用饼图代替Wedge\n",
    "        ax2.pie([completion, 1-completion], colors=['#3498DB', '#ECF0F1'], \n",
    "               startangle=90, wedgeprops=dict(width=0.3))\n",
    "        ax2.text(0, 0, f'{completion:.0%}', ha='center', va='center', \n",
    "                fontsize=16, fontweight='bold')\n",
    "        ax2.set_title('目标完成率', fontsize=12, fontweight='bold')\n",
    "        \n",
    "        # 3. 销售趋势\n",
    "        ax3 = fig.add_subplot(gs[1, 0])\n",
    "        months = ['1月', '2月', '3月', '4月', '5月', '6月']\n",
    "        sales_trend = [45000, 52000, 61000, 58000, 72000, 85000]\n",
    "        ax3.plot(months, sales_trend, 'o-', color='#3498DB', linewidth=2, markersize=4)\n",
    "        ax3.set_title('销售趋势', fontsize=12, fontweight='bold')\n",
    "        ax3.grid(True, alpha=0.3)\n",
    "        ax3.set_ylabel('销售额 (元)', fontsize=10)\n",
    "        \n",
    "        # 4. 商品分布\n",
    "        ax4 = fig.add_subplot(gs[1, 1])\n",
    "        categories = ['上衣', '裤子', '裙子', '配件']\n",
    "        category_sales = [45, 25, 20, 10]\n",
    "        ax4.pie(category_sales, labels=categories, autopct='%1.0f%%', \n",
    "               colors=self.colors[:4])\n",
    "        ax4.set_title('商品类别分布', fontsize=12, fontweight='bold')\n",
    "        \n",
    "        plt.suptitle('业务综合仪表盘', fontsize=16, fontweight='bold', y=0.95)\n",
    "        plt.tight_layout()\n",
    "        plt.savefig(f'{output_dir}/29_高级仪表盘.png', dpi=150, bbox_inches='tight')\n",
    "        plt.close()\n",
    "        \n",
    "    def chart30_comprehensive_analysis(self):\n",
    "        \"\"\"30. 综合分析图 - 多维度业务洞察\"\"\"\n",
    "        fig = plt.figure(figsize=(12, 8))\n",
    "        \n",
    "        # 创建网格布局\n",
    "        gs = fig.add_gridspec(2, 2)\n",
    "        \n",
    "        # 1. 销售趋势\n",
    "        ax1 = fig.add_subplot(gs[0, :])\n",
    "        months = ['1月', '2月', '3月', '4月', '5月', '6月']\n",
    "        sales_2023 = [45000, 52000, 61000, 58000, 72000, 68000]\n",
    "        sales_2024 = [48000, 56000, 65000, 62000, 78000, 85000]\n",
    "        \n",
    "        ax1.plot(months, sales_2023, 's-', color='#95A5A6', linewidth=2, \n",
    "                markersize=4, label='2023年', alpha=0.7)\n",
    "        ax1.plot(months, sales_2024, 'o-', color='#3498DB', linewidth=2, \n",
    "                markersize=5, label='2024年')\n",
    "        \n",
    "        ax1.set_title('销售趋势分析', fontsize=14, fontweight='bold')\n",
    "        ax1.set_ylabel('销售额 (元)', fontsize=10)\n",
    "        ax1.legend()\n",
    "        ax1.grid(True, alpha=0.3)\n",
    "        \n",
    "        # 2. 完成率\n",
    "        ax2 = fig.add_subplot(gs[1, 0])\n",
    "        completion = 0.82\n",
    "        ax2.pie([completion, 1-completion], colors=['#27AE60', '#ECF0F1'], \n",
    "               startangle=90)\n",
    "        ax2.text(0, 0, f'{completion:.0%}', ha='center', va='center', \n",
    "                fontsize=14, fontweight='bold')\n",
    "        ax2.set_title('季度完成率', fontsize=12, fontweight='bold')\n",
    "        \n",
    "        # 3. 增长指标\n",
    "        ax3 = fig.add_subplot(gs[1, 1])\n",
    "        metrics = ['用户增长', '收入增长', '利润增长']\n",
    "        rates = [0.15, 0.23, 0.18]\n",
    "        colors = ['#3498DB', '#27AE60', '#E74C3C']\n",
    "        \n",
    "        bars = ax3.bar(metrics, rates, color=colors, alpha=0.7)\n",
    "        ax3.set_title('增长指标', fontsize=12, fontweight='bold')\n",
    "        ax3.set_ylabel('增长率', fontsize=10)\n",
    "        \n",
    "        # 添加数值标签\n",
    "        for bar, rate in zip(bars, rates):\n",
    "            ax3.text(bar.get_x() + bar.get_width()/2, rate + 0.01, \n",
    "                    f'{rate:.1%}', ha='center', va='bottom', fontsize=9)\n",
    "        \n",
    "        plt.suptitle('业务综合分析', fontsize=16, fontweight='bold', y=0.95)\n",
    "        plt.tight_layout()\n",
    "        plt.savefig(f'{output_dir}/30_综合分析图.png', dpi=150, bbox_inches='tight')\n",
    "        plt.close()\n",
    "    \n",
    "    def generate_all_charts(self):\n",
    "        \"\"\"生成所有图表\"\"\"\n",
    "        print(\"开始生成第三部分图表 (21-30)...\")\n",
    "        \n",
    "        charts = [\n",
    "            self.chart21_bar_line_combo,\n",
    "            self.chart22_target_bar,\n",
    "            self.chart23_bullet_chart,\n",
    "            self.chart24_column_circle,\n",
    "            self.chart25_clustered_bar_line,\n",
    "            self.chart26_composite_bar,\n",
    "            self.chart27_bead_chart,\n",
    "            self.chart28_comparison_bead_chart,\n",
    "            self.chart29_advanced_dashboard,\n",
    "            self.chart30_comprehensive_analysis\n",
    "        ]\n",
    "        \n",
    "        for i, chart_func in enumerate(charts, 21):\n",
    "            try:\n",
    "                chart_func()\n",
    "                print(f\"✅ 图表 {i} 生成完成\")\n",
    "            except Exception as e:\n",
    "                print(f\"❌ 图表 {i} 生成失败: {str(e)}\")\n",
    "                import traceback\n",
    "                traceback.print_exc()\n",
    "        \n",
    "        print(f\"🎉 第三部分图表已保存到: {output_dir}\")\n",
    "        print(\"✨ 所有30个图表生成完成！\")\n",
    "\n",
    "# 运行第三部分\n",
    "if __name__ == \"__main__\":\n",
    "    data_path = r\"D:\\数据分析及可视化\\erp_order_data.xlsx\"\n",
    "    viz3 = VisualizationPart3(data_path)\n",
    "    viz3.generate_all_charts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8563578d-b309-4975-be20-ffc0835e5d05",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
